package com.example.springdataes.index;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.DateFormat;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import java.util.Date;

/**
 * 各种字段类型
 *
 * @author chenke
 * @version 1.0
 * @date 2022/5/30 20:47
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Document(indexName = "chenkeindex", shards = 1, replicas = 1)
public class ChenkeIndex {
    @Id
    @Field(type = FieldType.Long)
    private Long blogId;

    /**
     * Text可以分词analyzer = "ik_smart"
     */
    @Field(type = FieldType.Text)
    private String content;

    @Field(type = FieldType.Integer)
    private int status;

    /**
     * Keyword不分词的
     */
    @Field(type = FieldType.Keyword)
    private String type;

    @Field(type = FieldType.Double)
    private Double price;

    /**
     * index = false不需要被索引
     */
    @Field(type = FieldType.Keyword, index = false)
    private String images;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS")
    @Field(type = FieldType.Date, format = DateFormat.custom, pattern = "yyyy-MM-dd HH:mm:ss.SSS")
    private Date createTime;

}
